package com.lfnyxy.service.imp;

import com.lfnyxy.dao.ServerTypeDao;
import com.lfnyxy.dto.DropVo;
import com.lfnyxy.entity.ServerTypeEntity;
import com.lfnyxy.query.ServerTypeQuery;
import com.lfnyxy.service.ServerTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServerTypeServiceImp implements ServerTypeService {
    @Autowired
    public ServerTypeDao serverTypeDao;

    public int CreateItem(ServerTypeEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return serverTypeDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(ServerTypeEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return serverTypeDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <ServerTypeEntity> QueryPageList(ServerTypeQuery query) {
        int count = serverTypeDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return serverTypeDao.QueryPageList(query);
        }
        return null;
    }

    public List <ServerTypeEntity> QueryAll() {
        return serverTypeDao.QueryAll();
    }

    public ServerTypeEntity QueryItem(int Id) {
        if (Id > 0) {
            return serverTypeDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return serverTypeDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    @Override
    public List <DropVo> QueryDrop() {
        return serverTypeDao.QueryDrop();
    }

    private boolean CheckIsExist(ServerTypeEntity entity) {
        if (entity != null) {
            return serverTypeDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}